﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;

namespace SemestralniPraceY35VAN
{
    class Score
    {
        /// <summary>
        /// Properties of the score.
        /// </summary>
        private Hashtable properties;

        /// <summary>
        /// 
        /// </summary>
        public int Points { get { if (properties.ContainsKey("points")) return Int16.Parse((string)properties["points"]); else return 0; } }

        /// <summary>
        /// 
        /// </summary>
        public Image Icon
        {
            get
            {
                if (!properties.ContainsKey("icon"))
                {
                    properties.Add("icon", Downloader.DownloadImage((string)properties["iconurl"]));
                }

                return (Image)properties["icon"];
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public string Message { get { if (properties.ContainsKey("message")) return (string)properties["message"]; else return null; } }

        /// <summary>
        /// Constructs an object representing a score.
        /// </summary>
        /// <param name="score">XML node with information about the score</param>
        public Score(XmlNode score)
        {
            properties = new Hashtable();

            if (score.Name == "score")
            {
                for (int i = 0; i < score.ChildNodes.Count; i++)
                {
                    switch (score.ChildNodes[i].Name)
                    {
                        case "icon":
                            properties.Add("iconurl", score.ChildNodes[i].InnerText);
                            break;
                        default:
                            properties.Add(score.ChildNodes[i].Name, score.ChildNodes[i].InnerText);
                            break;
                    }
                }
            }
            else
            {
                throw new IOException("Not Score!");
            }
        }
    }
}
